<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        ul,li,a{
            list-style: none;
            text-decoration: none;
        }
    </style>
</head>
<body>
    <div id="app">
        <h2>日常工作列表：</h2>
        <input type="text" v-model="newWork" @keyup.enter='addWork'/>
        <button @click='addWork'>添加英雄</button>
        <ul>
            <li v-for="(i,index) in workArr">
                <span>序号{{i.id}}:</span>
                <span>{{i.work}} </span>
                <a href="#" @click="rem(index)">X</a>
            </li>   
        </ul>
    </div>

    <script src="./js/vue.js"></script>
    <script>
        let app = new Vue({
            el:'#app',
            data:{
                newWork:"",
                workArr:[]
            },
            methods:{
                addWork(ev){
                    console.log(this.newWork);
                    if(this.newWork === ''){
                        return;
                    }
                    let arr = new Object();
                    this.index = this.workArr.length;
                    arr.id = this.index+1;
                    arr.work = this.newWork;
                    this.workArr.push(arr);
                    this.newWork = '';
                },
                rem(index){
                   this.workArr.splice(index,1);
                }
            }
        });
    </script>
</body>
</html>